var defaultUpdatePeriod = 1800;
var userDataBlob = "./blob/userInfoLight.php";
var userPlanetsLink = "./blob/userPlanetsLink.php";
var userEventsLink = "./blob/userEventsLink.php";
var mainMessages = "./blob/mainMessages.php";


var jsonRequest = Class.create(
{
    initialize: function(error,error_number,type,operation,data)
    {
        this.error = error;
        this.error_number = error_number;
        this.type = type;
        this.operation = operation;
        this.data = data;
    }
});

function executeRequest(URI, successFunction, failureFunction)
{
    new Ajax.Request(URI,
    {
        method:'get',
        onSuccess:successFunction,
        onFailure:failureFunction
    });
}

function ajaxUpdater(itemId, URI)
{
    new Ajax.Updater(itemId,URI);
}

function ajaxBinder(itemId,URI, period)
{
    new Ajax.PeriodicalUpdater(itemId, URI,
    {
        method: 'get',
        frequency: period,
        decay: 1
    });
}

function firstPageLoad()
{
    /*BINDINGS*/
    
    /*Bind user ui common data*/
    loadUserCommonData();
    loadUserPlanets();
    loadUserActiveEvents();    
}

function loadUserCommonData()
{
    //json = new jsonRequest(0,0,1,0,null);
    //ajaxBinder('header',userDataBlob+Object.toJSON(json),defaultUpdatePeriod);
    ajaxBinder('header',userDataBlob,defaultUpdatePeriod);
}

function loadUserPlanets()
{
    ajaxBinder('planetLinks',userPlanetsLink,defaultUpdatePeriod);
}

function loadUserActiveEvents()
{
    ajaxBinder('top_menu_center',userEventsLink,defaultUpdatePeriod);
}

function loadMessages()
{
    ajaxBinder('messages',mainMessages,defaultUpdatePeriod);
}

function showMessage(messageId)
{
var winparent = $("open");
changeSection(5);
var newRequest = new jsonRequest(0,0,0,0,messageId);
var url = '../blob/detailMessage.php?jsonraw=' + Object.toJSON(newRequest);

while(url.indexOf("\"")>0)
{
    url = url.replace("\"","@");
}

var win = new Window({className: "mac_os_x",
                    title: "Messages", 
                    top:70,
                    left:100,
                    width:300,
                    height:200,
                    url: url,
                    parent:winparent,
                    maxWidth:winparent.scrollWidth*0.95,
                    maxHeight:winparent.scrollHeight*0.85,
                    showEffectOptions: {duration:0.3}})
win.show();  
}
